using System;
using System.Collections.Generic;
using System.Text;
using gudusoft.gsqlparser;
using gudusoft.gsqlparser.Units;

using System.Threading;


namespace pettest
{
    public class performanceTest
    {
        public void doit()
        {
            int loops = 3000;
            int c = Environment.TickCount;
            for (int k = 0; k < loops; k++)
            {
                TGSqlParser sqlParser = new TGSqlParser(TDbVendor.DbVMssql);
                sqlParser.SqlText.Text = @"select a,b,c from b where a>1 group by a having c>1 order by 1,2";
                sqlParser.Parse();
            }
            Console.WriteLine("Loops: {0}, Time escaped: {1}", loops, Environment.TickCount - c);
        }
    }

    class pertest
    {
        static void Main(string[] args)
        {
            Console.WriteLine("start...");
            performanceTest p = new performanceTest();
            performanceTest p1 = new performanceTest();
            performanceTest p2 = new performanceTest();
            performanceTest p3 = new performanceTest();
            performanceTest p4 = new performanceTest();
            performanceTest p5 = new performanceTest();
            performanceTest p6 = new performanceTest();
            performanceTest p7 = new performanceTest();
            performanceTest p8 = new performanceTest();
            performanceTest p9 = new performanceTest();
            performanceTest p10 = new performanceTest();

            Thread oThread = new Thread(new ThreadStart(p.doit));
            Thread oThread1 = new Thread(new ThreadStart(p1.doit));
            Thread oThread2 = new Thread(new ThreadStart(p2.doit));
            Thread oThread3 = new Thread(new ThreadStart(p3.doit));
            Thread oThread4 = new Thread(new ThreadStart(p4.doit));
            Thread oThread5 = new Thread(new ThreadStart(p5.doit));
            Thread oThread6 = new Thread(new ThreadStart(p6.doit));
            Thread oThread7 = new Thread(new ThreadStart(p7.doit));
            Thread oThread8 = new Thread(new ThreadStart(p8.doit));
            Thread oThread9 = new Thread(new ThreadStart(p9.doit));
            Thread oThread10 = new Thread(new ThreadStart(p10.doit));

            oThread.Start();
            oThread1.Start();
            oThread2.Start();
            oThread3.Start();
            oThread4.Start();
            oThread5.Start();
            oThread6.Start();
            oThread7.Start();
            oThread8.Start();
            oThread9.Start();
            oThread10.Start();

            oThread.Join();
            oThread1.Join();
            oThread2.Join();
            oThread3.Join();
            oThread4.Join();
            oThread5.Join();
            oThread6.Join();
            oThread7.Join();
            oThread8.Join();
            oThread9.Join();
            oThread10.Join();

            Console.WriteLine("main thread over");
            return;

            if (args.Length != 2)
            {
                Console.WriteLine("Usage: pettest {0} {1}", "count", "isglobal");
                return;
            }

            int c = Environment.TickCount;
            Console.WriteLine("start...");

            TGSqlParser sqlParser = new TGSqlParser(TDbVendor.DbVMssql);
            int count = Convert.ToInt16(args[0]);
            bool isGlobal = args[1].Equals("g");

            for (int k = 0; k < count; k++)
            {
                if (isGlobal)
                {
                    //global instance
                }
                else
                {
                    sqlParser = new TGSqlParser(TDbVendor.DbVMssql);
                }

                sqlParser.SqlText.Text = @"select a,b,c from b where a>1 group by a having c>1 order by 1,2";
                //sqlParser.Sqlfilename = @"D:\prg\gsqlparser\tmp\demo.sql";
                int i = sqlParser.Parse();

                if (i == 0)
                {
                    //Console.WriteLine("done");

                }
                else
                {
                    Console.WriteLine("e:" + sqlParser.ErrorMessages);
                }

            }

            Console.WriteLine("global: {0}, Loops: {1}, Time escaped: {2}", isGlobal, count, Environment.TickCount - c);

        }
    }
}
